package com.onetime.mall.trading.controller;

import com.onetime.mall.trading.entity.LabelEntity;
import com.onetime.mall.trading.service.LabelService;
import com.onetime.mall.trading.utils.PageUtils;
import com.onetime.mall.trading.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * @author liyixuan
 * @email liyixuan106@163.com
 * @date 2022-04-28 18:19:16
 */
@RestController
@RequestMapping("trading/label")
public class LabelController {
    @Autowired
    private LabelService labelService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = labelService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id) {
        LabelEntity label = labelService.getById(id);

        return R.ok().put("label", label);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody LabelEntity label) {
        labelService.save(label);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody LabelEntity label) {
        labelService.updateById(label);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids) {
        labelService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
